package whf.framework.meta.entity;

import java.sql.Timestamp;
import java.util.Set;

import whf.framework.meta.Meta;
import whf.framework.util.StringUtils;
import whf.framework.util.Utils;

/**
 * 对象描述meta类
 * @author wanghaifeng
 *
 */
public class Object extends AbstractMeta<ObjectProperty> {
	private final static long serialVersionUID = 0;

	/**
	 * @property Object:parent
	 */
	private Object parent;
	
	/**
	 * 业务对象类名
	 * @property String:boClassName
	 */
	private String boClassName;
	
	/**
	 * struts action类名
	 * @property String:actionClassName
	 */
	private String actionClassName;
	
	/**
	 * 服务类名
	 * @property String:serviceClassName
	 */
	private String serviceClassName;
	
	/**
	 * Spring服务名称
	 * @property String:serviceName
	 */
	private String serviceName;
	
	/**
	 * Dao类名
	 * @property String:daoClassName
	 */
	private String daoClassName;
	
	/**
	 * Spring dao名称
	 * @property String:daoName
	 */
	private String daoName;
	
	/**
	 * 对应的数据库表名
	 * @property String:persistenceTable
	 */
	private String persistenceTable;
	
	/**
	 * @property String:parentBoClassName
	 */
	private String parentBoClassName;
	
	/**
	 * @property String:validationName
	 */
	private String validationName;
	
	/**
	 * @property String:subModule
	 */
	private String subModule;

	/**
	 * 访问的路径
	 * @property String:path
	 */
	private String path;
	
	/**
	 * 对象类型:框架对象,业务对象等,使用名称表示
	 * @property String:objectType
	 */
	private String objectType;
	
	/**
	 * 决定是否记录日志
	 * @modify 2008-1-21 下午09:54:58
	 */
	private boolean auditable;
	
	/**
	 * 最近执行索引时间，用在手工建立索引中；
	 * @modify 2008-1-24 下午03:44:12
	 */
	
	private Timestamp lastIndexTime;
	
	private String branch;
	
	public Object(){
		super();
	}
	
	public Object getParent() {
		return parent;
	}

	public void setParent(Object parent) {
		this.parent = parent;
	}

	public String getActionClassName() {
		return actionClassName;
	}

	public void setActionClassName(String actionClassName) {
		this.actionClassName = actionClassName;
	}

	public String getBoClassName() {
		return boClassName;
	}

	public void setBoClassName(String boClassName) {
		this.boClassName = boClassName;
	}

	public String getDaoClassName() {
		return daoClassName;
	}

	public void setDaoClassName(String daoClassName) {
		this.daoClassName = daoClassName;
	}

	public String getDaoName() {
		return daoName;
	}

	public void setDaoName(String daoName) {
		this.daoName = daoName;
	}

	public String getParentBoClassName() {
		return parentBoClassName;
	}

	public void setParentBoClassName(String parentBoClassName) {
		this.parentBoClassName = parentBoClassName;
	}

	public String getPersistenceTable() {
		return persistenceTable;
	}

	public void setPersistenceTable(String persistenceTable) {
		this.persistenceTable = persistenceTable;
	}

	public String getServiceClassName() {
		return serviceClassName;
	}

	public void setServiceClassName(String serviceClassName) {
		this.serviceClassName = serviceClassName;
	}

	public String getServiceName() {
		return serviceName;
	}

	public void setServiceName(String serviceName) {
		this.serviceName = serviceName;
	}
	
	public String getValidationName() {
		return validationName;
	}

	public void setValidationName(String validationName) {
		this.validationName = validationName;
	}
	
//	@Override
//	public void setProperties(Set<IProperty> objectProperties) {
//		super.setProperties(objectProperties);
//		for(IProperty p: objectProperties){
//			((ObjectProperty)p).setBoObject(this);
//		}
//	}

	public String getSubModule() {
		return subModule;
	}

	public void setSubModule(String subModule) {
		this.subModule = subModule;
	}

	/**
	 * @return Returns the path.
	 */
	public String getPath() {
		return path;
	}

	/**
	 * @param path The path to set.
	 */
	public void setPath(String path) {
		this.path = path;
	}

	/**
	 * @return Returns the objectType.
	 */
	public String getObjectType() {
		return objectType;
	}

	/**
	 * @param objectType The objectType to set.
	 */
	public void setObjectType(String objectType) {
		this.objectType = objectType;
	}

	public boolean equals(java.lang.Object obj){
		if(obj == null || !(obj instanceof Object)) return false;
		return StringUtils.equalsIgnoreCase(this.boClassName, ((Object)obj).getBoClassName());
	}

	public Meta toMeta(){
		Meta meta = new Meta();
		meta.setActionClass(Utils.getClassByClassName(this.actionClassName));
		meta.setDaoClass(Utils.getClassByClassName(this.daoClassName));
		meta.setDaoName(this.daoName);
		meta.setId(this.getId());
		meta.setModelClass(Utils.getClassByClassName(this.boClassName));
		meta.setName(this.getName());
		meta.setParentModelClass(Utils.getClassByClassName(this.parentBoClassName));
		meta.setPersistenceTable(this.getPersistenceTable());
		meta.setRemarks(this.getRemarks());
		meta.setServiceClass(Utils.getClassByClassName(this.getServiceClassName()));
		meta.setServiceName(this.getServiceName());
		meta.setValidationName(this.validationName);
		Set<IProperty> properties = Utils.newHashSet();
		properties.addAll(this.getProperties());
		meta.setProperties(properties);
		meta.setBranch(branch);
		return meta;
	}

	/**
	 * @return the auditable
	 */
	public boolean isAuditable() {
		return auditable;
	}

	/**
	 * @param auditable the auditable to set
	 */
	public void setAuditable(boolean auditable) {
		this.auditable = auditable;
	}

	/**
	 * @return the lastIndexTime
	 */
	public Timestamp getLastIndexTime() {
		return lastIndexTime;
	}

	/**
	 * @param lastIndexTime the lastIndexTime to set
	 */
	public void setLastIndexTime(Timestamp lastIndexTime) {
		this.lastIndexTime = lastIndexTime;
	}

	public String getBranch() {
		return branch;
	}

	public void setBranch(String branch) {
		this.branch = branch;
	}
}
